package org.cst8277.ums.util;

import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;

import java.security.MessageDigest;

@Slf4j
@UtilityClass
public class Md5Util {
    public static String md5sum(String data) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] dataBytes = data.getBytes();
            byte[] mdBytes = md.digest(dataBytes);
            StringBuilder sb = new StringBuilder();
            for (byte b : mdBytes) {
                sb.append(String.format("%02x", b & 0xff));
            }
            return sb.toString();
        } catch (Exception ex) {
            log.error("md5sum计算出错:{}", data);
        }
        return null;

    }

    public static void main(String[] args) {
        String md5sum = Md5Util.md5sum("我是樊长利");
        log.info("md5sum:{}", md5sum);
    }

}
